﻿///******************************************************    
///	FileName: Supply.js
///	Action: 会员中心供应页面JS处理文件
///	Copyright(c)  2004-2008 网胜科技公司技术开发部
///	Writer: XFY
///	Create Date: 2008-12-17
///	Rewriter:
///	Rewrite Date:
///****************************************************** 
var rightIcon="../images/websen.gif"
var rightIcons="../../images/icon_nothing.gif";
var txtjbo=new  Array("ctl00_ContInfo_txtName","ctl00_ContInfo_txtKey","ctl00_ContInfo_txtPlace","ctl00_ContInfo_txtBrand","ctl00_ContInfo_txtModel","ctl00_ContInfo_txtPrice","ctl00_ContInfo_txtQuantity","ctl00_ContInfo_txtMinimum")

//得到焦点
for(var i=0;i<txtjbo.length;i++){ 
    $(txtjbo[i]).onfocus =function (){
        for (var j=0;j<txtjbo.length;j++){
            if (txtjbo[j]==event.srcElement.id){postobj(j);}
        }
    }
}

function postobj(num){
    obj = "txt"+num;
    document.getElementById(obj).innerHTML =supply[num];
}

function oo(){$("yc").style.display="none"}
//失去焦点

for(var i=0;i<txtjbo.length;i++){ 
    $(txtjbo[i]).onblur =function (){for (var j=0;j<txtjbo.length;j++){
        if (txtjbo[j]==event.srcElement.id){
            postobjs(j);}
        }
    }
}

function postobjs(num){
    var obj="txt"+num;
    if ($(obj).innerHTML!=""){
        $(obj).innerHTML=""
    }else {
        $(obj).innerHTML=ok;
    }
}

function getobj(objName){
    if ($) {
        return eval('$("'+ objName +'")');
    }else {
        return eval('document.all["'+ objName +'"]');
    }
}

//提交函数
$("ctl00_ContInfo_btnSave").onclick=function Server(){
    var  Sukly = new Array(5)
    var variale=0;
    var vali=0;
 var rep=/^(0|[1-9]\d*)(\.\d{1,2})?$/;
 var reprice=new RegExp(rep);
    Sukly[0]=supplys(txtjbo[0],0,0)
    Sukly[1]=supplys(txtjbo[1],1,0)
    Sukly[2]=supplys(txtjbo[5],5,0) 
    Sukly[3]=supplys(txtjbo[6],6,3)
    Sukly[4]=supplys(txtjbo[7],7,4)
    if(document.getElementById("ctl00_ContInfo_txtName").value.trim()==""){
        variale=1;
    }
    if(document.getElementById("ctl00_ContInfo_txtKey").value.trim()=="")
    {
         variale=1;
    }
    if((parseInt($("ctl00_ContInfo_txtQuantity").value))!=0){
    if((parseInt($("ctl00_ContInfo_txtMinimum").value))>(parseInt($("ctl00_ContInfo_txtQuantity").value))){
           document.getElementById("txt6").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>供货总量不能小于最小起定量</font>";
            vali=1;
         }
         }else{
         document.getElementById("txt6").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>供货总量必须大于0小于9999999</font>";
         vali=1;
         }
    
    
    if ($("ctl00_ContInfo_SortB").selectedIndex == -1) {
	         document.getElementById("txt02").innerHTML = "<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>请选择所属行业和产品类目！</font>";
	         variale=1;
    }
  else if ($("ctl00_ContInfo_SortM").options.length > 0 && $("ctl00_ContInfo_SortM").selectedIndex == -1) {
	        document.getElementById("txt02").innerHTML = "<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>您的类目没有选择完整，请继续选产品大类。</font>";
	        variale=1;
    }
  else if ($("ctl00_ContInfo_SortS").options.length > 0 && $("ctl00_ContInfo_SortS").selectedIndex == -1) {
	        document.getElementById("txt02").innerHTML = "<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>您的类目没有选择完整，请继续选择产品子类。</font>";
	       variale=1;
    }else
    {
       document.getElementById("txt02").innerHTML="";
    }
     if($("ctl00_ContInfo_txtPrice").value!=0){
       if(!(rep.test($("ctl00_ContInfo_txtPrice").value))){ 
         document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
         vali=1;
        }
      }else{
          document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
          vali=1;
      }
      if((parseInt($("ctl00_ContInfo_txtMinimum").value))!=0){
     if((parseInt($("ctl00_ContInfo_txtMinimum").value))>(parseInt($("ctl00_ContInfo_txtQuantity").value))){
           document.getElementById("txt7").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>最小起定量不能大于供货总量</font>";
          vali=1;
     }}else{
        document.getElementById("txt7").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>最小起定量必须大于0小于9999999</font>";
        vali=1;
     }
     if(variale!=0){
         window.location.href="#flagKeyword";
         return false;
     }else if(vali!=0){
          window.location.href="#flagtiaojian";
         return false;
     }
     else{
         document.getElementById("txt5").innerHTML="";
        return true;
     }
    var flag=1;
    for (i=0;i<Sukly.length;i++){
        if (Sukly[i]==false){
            flag=0;
            break;
        } 
    } 
    if(flag==0){
        return false
    } 
   else{
       return true;
   }
}

//方法
function supplys(name,num,bernum){
    var obj="txt"+num
    if($(name).value.replace(/\s/g,'')==""){
        $(obj).innerHTML=GyFb[num]
        return false;
    } else if(bernum==1){
        if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''))) {
            $(obj).innerHTML=GyFb[8];
            return false 
        }else{
            $(obj).innerHTML=ok
            return true
        }  
    }else if(bernum==2){
        if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''),1)) {
            $(obj).innerHTML=GyFb[8];
            return false 
        }else{           
            $(obj).innerHTML=ok
            return true
        }  
    }else if(bernum==3){
            if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''),1)) {
                 $(obj).innerHTML=GyFb[8];
                  return false 
            }else{           
                 if(!isValueSize(getobj(txtjbo[num]).value.replace(/\s/g,''),1)){
                    $(obj).innerHTML=GyFb[9];
                     return false
                 }else{
                     $(obj).innerHTML=ok
                     return true
                 }
        }
    }else if(bernum==4){
         if (!isNumber(getobj(txtjbo[num]).value.replace(/\s/g,''))) {
            $(obj).innerHTML=GyFb[8];             
            return false 
        }else{
             if(!isValueSize(getobj(txtjbo[num]).value.replace(/\s/g,''),2)){
                $(obj).innerHTML=GyFb[10];
                 return false
             }else{
                 $(obj).innerHTML=ok
                 return true
             }
        }  
    }else{
        $(obj).innerHTML=ok
        return true
    }
    return true
}
//显示信息
var ok="<font color='red'></font>";
var title="<p>";
var titles="</p>"
var supply=new Array()
supply[0]=title+"<font color='red'>产品名称中请勿出现规格、型号、品牌等内容。<font>"+titles
supply[1]=title+"<font color='red'>关键字用逗号隔开。例如：“超轻电脑桌,可折叠电脑桌”。</font>"+titles
supply[2]=title+"<font color='red'>请输入生产家地址,尽可能详细点，例如:北京市海淀区怡海广场西座28B </font>"+titles
supply[3]=title+"<font color='red'>请输入该产品的品牌名称,例如:安踏,361,海尔。</font>"+titles
supply[4]=title+"<font color='red'>请输入该产品的型号,例如:CCZG-2A型,CCZ-20A型</font>"+titles
supply[5]=""
supply[6]=""
supply[7]=""



//供应信息
var GyFb=new Array();
GyFb[0]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>产品名称不能为空</font>";
GyFb[1]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>关键字名称不能为空</font>";
GyFb[2]="<font></font>";
GyFb[3]="<font></font>";
GyFb[4]="<font></font>";
GyFb[5]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";
GyFb[6]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";
GyFb[7]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";
GyFb[8]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>输入不符合规范,请输入数字!</font>";
GyFb[9]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>供货总量必须是大于0小于9999999的值!</font>";
GyFb[10]="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>最小起定量必须是大于0小于9999999的值!</font>";


var rep=/^(0|[1-9]\d*)(\.\d{1,2})?$/;
var reprice=new RegExp(rep);
$("ctl00_ContInfo_txtPrice").onblur=function(){
      if($("ctl00_ContInfo_txtPrice").value!=0){
        if(!(rep.test($("ctl00_ContInfo_txtPrice").value))){ 
            document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价格式不正确</font>";
            return false;
        }
        else{
            document.getElementById("txt5").innerHTML="";
            return true;
        } 
    }else
    {
     document.getElementById("txt5").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>单价必须大于0小于9999999</font>";
    }
}

$("ctl00_ContInfo_txtMinimum").onblur=function(){
  if((parseInt($("ctl00_ContInfo_txtMinimum").value))!=0){
   if((parseInt($("ctl00_ContInfo_txtMinimum").value))>(parseInt($("ctl00_ContInfo_txtQuantity").value))){
           document.getElementById("txt7").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>最小起定量不能大于供货总量</font>";
           return false;
         } 
     else{
            document.getElementById("txt7").innerHTML="";
        } 
        }else{
         document.getElementById("txt7").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>最小起定量必须大于0小于9999999</font>";
          return false;
        }   
  }

$("ctl00_ContInfo_txtName").onblur=function(){
   if(document.getElementById("ctl00_ContInfo_txtName").value.trim()=="")
   {
        document.getElementById("txt0").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>产品名称不能为空</font>";
        return false;
    }
}

$("ctl00_ContInfo_txtKey").onblur=function(){
 if(document.getElementById("ctl00_ContInfo_txtKey").value.trim()==""){
             document.getElementById("txt1").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>产品关键字不能为空</font>";
             return false;
} }
$("ctl00_ContInfo_txtQuantity").onblur=function(){
if((parseInt($("ctl00_ContInfo_txtQuantity").value))!=0){
   if((parseInt($("ctl00_ContInfo_txtMinimum").value))>(parseInt($("ctl00_ContInfo_txtQuantity").value))){
           document.getElementById("txt6").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>供货总量不能小于最小起定量</font>";
           return false;
         } 
     else{
            document.getElementById("txt6").innerHTML="";
        } 
        }else{
        
          document.getElementById("txt6").innerHTML="<img src="+rightIcon+" align=\"absmiddle\"> <font color=#FF0000>供货总量必须大于0小于9999999</font>";
          return false;
        }  
  }